/**
 * 
 */
package com.mc.fastjson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * @author w.weizhen
 *
 */
public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
//		orgType();
		
//		orgEcnoType();
		
//		//json字符串转对象
//		String json = "{}";
//		JSONArray datas = JSON.parseArray(orgEcnoTypes);
//		JSONObject data = JSON.parseObject(json);
//		JSON.parse(json);
//		System.out.println(data.isEmpty());
		
		// 观察字符串转对象是否保存
//		String json = "{\"errCode\":401, \"message\":Unauthorized}";
//		JSONObject data = JSON.parseObject(json);
//		
//		//生成和观察字符串生成结构
//		JSONObject data = new JSONObject();
//		data.put("personId", "119f9121af4c4a8aa67883ecd9fb4e62");
//		data.put("faceFileId", "group8/HY00/00/03/4a4142b522a9435989314090d880d456.jpg");
//		data.put("createAccountId", "abd0eea56c0341e5a5e25b19d850f6d9");
//		System.out.println(data);
//		//移除指定key信息
//		data.remove("faceFileId");
//		data.remove("personIdx");
//		System.out.println(data);
//		
//		JSONObject data = new JSONObject();
//		data.put("personCode", "d0367afe50f54fb5b7a1d5a46b7f54c7");
//		data.put("personName", "李平");
//		System.out.println(data);
		
		// 查看目录地址
//		System.out.println(System.getProperty("java.io.tmpdir"));
		
		
//		listToJsonArray();
		
//		JSONArray datas = new JSONArray();
//		JSONObject data = JSON.parseObject("{'index':'00','name':'0N'}");
//		datas.add(data);
//		System.out.println(datas);
//		System.out.println(datas.get(0));
//		data = JSON.parseObject("{'index':'01','name':'1N'}");
//		datas.add(data);
//		System.out.println(datas);
//		System.out.println(datas.get(0));
		
//		List<String> datas = new ArrayList<String>();
//		datas.add("00");
//		System.out.println(datas.get(0));
//		datas.remove(0);
//		datas.add("01");
//		System.out.println(datas.get(0));
//		datas.add("02");
//		System.out.println(datas.get(0));
		
	}
	
	private static void orgType()
	{
		String orgType = "['汽车修理与维护','长途客运','汽车新车零售','包装装潢及其他印刷','其他电子器件制造','其他医疗设备及器械制造','工业自动控制系统装置制造','金属工艺品制造','包装服务','汽车、摩托车等修理与维护','橡胶板、管、带制造','纺织带和帘子布制造','电影放映','集成电路制造','其他通用仪器制造','其他电子专用设备制造','其他出版业','通信终端设备制造','供应用仪器仪表制造','本册印制','建筑幕墙装饰和装修','其他会议、会展及相关服务','塑料零件及其他塑料制品制造','口腔科用设备及器具制造','其他计算机制造','半导体分立器件制造','塑料丝、绳及编织品制造','木制容器制造','首饰、工艺品及收藏品批发','通用仓储','其他道路运输辅助活动','其他未列明金属制品制造','糕点、面包制造','危险化学品仓储','教学专用仪器制造','其他专用设备制造','日用塑料制品制造','出租车客运','医疗用品及器材批发','其他电子元件制造','其他贸易经纪与代理','水产品冷冻加工','塑料包装箱及容器制造','记录媒介复制','检测服务','石油及制品批发','其他专用仪器制造','其他食品批发','其他纸制品制造','电子电路制造','金属切削机床制造','冶金专用设备制造','配电开关控制设备制造','加工纸制造','药用辅料及包装材料','其他文教办公用品制造','其他未列明批发业']";
		String key = "['O8111', 'G5421', 'F5261', 'C2319', 'C3979', 'C3589', 'C4011', 'C2432', 'L7292', 'O811', 'C2912', 'C1783', 'R8760', 'C3973', 'C4019', 'C3569', 'R8629', 'C3922', 'C4016', 'C2312', 'E5013', 'L7289', 'C2929', 'C3582', 'C3919', 'C3972', 'C2923', 'C2035', 'F5146', 'G5920', 'G5449', 'C3399', 'C1411', 'G5942', 'C4026', 'C3599', 'C2927', 'G5413', 'F5154', 'C3989', 'F5189', 'C1361', 'C2926', 'C2330', 'M7452', 'F5162', 'C4029', 'F5129', 'C2239', 'C3982', 'C3421', 'C3516', 'C3823', 'C2223', 'C2780', 'C2419', 'F5199']";
		String asc= "[{num:'65',key:'A'},{num:'66',key:'B'},{num:'67',key:'C'},{num:'68',key:'D'},{num:'69',key:'E'},{num:'70',key:'F'},{num:'71',key:'G'},{num:'72',key:'H'},{num:'73',key:'I'},{num:'74',key:'J'},{num:'75',key:'K'},{num:'76',key:'L'},{num:'77',key:'M'},{num:'78',key:'N'},{num:'79',key:'O'},{num:'80',key:'P'},{num:'81',key:'Q'},{num:'82',key:'R'},{num:'83',key:'S'},{num:'84',key:'T'},{num:'85',key:'U'},{num:'86',key:'V'},{num:'87',key:'W'},{num:'88',key:'X'},{num:'89',key:'Y'},{num:'90',key:'Z'}]";
		JSONArray orgTypes = JSON.parseArray(orgType);
		JSONArray keys = JSON.parseArray(key);
		JSONArray ascs = JSON.parseArray(asc);
		String insert  = "INSERT INTO `t_dictionary_org` (`id`, `orgId`, `paramType`, `paramValue`, `paramKey`, `paramzh`, `paramzhtw`, `paramen`, `sysId`, `seq`) VALUES ";
//		System.out.println(orgTypes.size());
//		System.out.println(keys.size());
		for (int i = 0; i < orgTypes.size(); i++) 
		{
			String uuid=UUID.randomUUID().toString().replaceAll("-", "");
			String name = orgTypes.getString(i);
			String value = keys.getString(i);
			String type = null;
			for (int j = 0; j < ascs.size(); j++) 
			{
				
				if(value.indexOf(ascs.getJSONObject(j).getString("key"))>-1)
				{
					type = value.replace(ascs.getJSONObject(j).getString("key"), ascs.getJSONObject(j).getString("num"));
					break;
				}
			}
//			System.out.println(data);
			Integer index = 100 + i;
			String sql = "('"+uuid+"', '', 'orgType', '"+type+"', '"+value+"', '"+name+"', '"+name+"', '"+name+"', 'b45e77758fa1445fafdc1100e20d8bfa', "+index+");";
			System.out.println(insert + sql);
		}
	}
	
	private static void orgEcnoType()
	{
		String orgEcnoTypes = "['私营合伙企业','私营有限责任公司','私营股份有限公司','个体企业','私营独资企业','港、澳、台商投资企业','合资经营企业（港或澳、台资）','股份合作企业','国有与集体联营企业','中外合资经营企业','国有独资公司','外商投资股份有限公司','港、澳、台商独资经营企业','其他企业']";
		JSONArray datas = JSON.parseArray(orgEcnoTypes);
		String insert  = "INSERT INTO `t_dictionary_org` (`id`, `orgId`, `paramType`, `paramValue`, `paramKey`, `paramzh`, `paramzhtw`, `paramen`, `sysId`, `seq`) VALUES ";
		for (int i = 0; i < datas.size(); i++) 
		{
			String uuid=UUID.randomUUID().toString().replaceAll("-", "");
			String data = datas.getString(i);
//			System.out.println(data);
			Integer index = 9 + i;
			String sql = "('"+uuid+"', '', 'orgEcnoType', 'orgEcnoType_"+index+"', 'orgEcnoType_"+index+"', '"+data+"', '"+data+"', '"+data+"', 'b45e77758fa1445fafdc1100e20d8bfa', "+index+");";
			System.out.println(insert + sql);
		}
	}
	
	
	private static void edit()
	{
		JSONArray datas = new JSONArray();
        for (int i = 0; i < 12; i++) {
        	JSONObject data = new JSONObject();
            data.put(Math.floor(Math.random() * Math.floor(100))+"", Math.floor(Math.random() * Math.floor(100))+"");
            datas.add(data);
//            System.out.println(data.toJSONString());
        }
//		System.out.println(datas.toJSONString());
		
		int size = datas.size();
		for (int i = 0; i < size - 10; i++)
        {
            datas.remove(0);
        }
		System.out.println(datas.toJSONString());
		
	}
	
	private static void listToJsonArray()
	{
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < 10; i++) 
		{
			list.add(String.valueOf(Math.floor(Math.random() * Math.floor(100))));
		}
		System.out.println(list);
		JSONObject data = new JSONObject();
		data.put("data", list);
		JSONArray datas = data.getJSONArray("data");
		System.out.println(datas);
		List<String> datas_str = datas.toJavaList(String.class);
		System.out.println(datas_str);
		datas_str = JSON.parseArray(data.getString("data"), String.class);
		System.out.println(datas_str);
	}
	
	
	
	
}